import 'dart:convert';

import 'package:car_baidu/core/model/l_l_car_list_model_entity.dart';
import 'package:car_baidu/core/model/l_l_user_info_model_entity.dart';
import 'package:car_baidu/core/model/login_info_model.dart';

import 'data/data.dart';
import 'data/share_data_contants.dart';

class LLInitializeData {
  static bool isLogin = false;
  static LLLoginInfoModel? loginModel;
  static LLCarListModelEntity? carListModel;
  static LLUserInfoModelEntity? userInfoModel;
  static bool isFirstLogin = false;
  static Future<bool> initialize() async {
    // 获取登陆数据,并进行model化
    String? loginInfo =
        await LLShareData.getString(LLShareDataContants.loginInfo);
    if (loginInfo != null) {
      isLogin = true;
      loginModel = LLLoginInfoModel.fromJson(json.decode(loginInfo));
    }

    String? carListInfo =
        await LLShareData.getString(LLShareDataContants.carListInfo);
    if (carListInfo != null) {
      carListModel = LLCarListModelEntity().fromJson(json.decode(carListInfo));
    }

    String? userInfo =
        await LLShareData.getString(LLShareDataContants.userInfo);
    if (userInfo != null) {
      userInfoModel = LLUserInfoModelEntity().fromJson(json.decode(userInfo));
    }

    bool? isFirstLogin =
        await LLShareData.getBool(LLShareDataContants.isFirstLoginApp);
    if (isFirstLogin != null) {
      isFirstLogin = isFirstLogin;
    } else {
      isFirstLogin = true;
    }

    return true;
  }

  static comeApp() {
    LLShareData.setBool(LLShareDataContants.isFirstLoginApp, false);
  }
}
